#include "mainwindow.h"
#include "ui_mainwindow.h"
#include  <QImage>
#include  <QDebug>
#include "v4l2.h"
#include "ffmpeg.h"

extern "C"{
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <time.h>
    #include <libavutil/avassert.h>
    #include <libavutil/channel_layout.h>
    #include <libavutil/opt.h>
    #include <libavutil/mathematics.h>
    #include <libavutil/timestamp.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include <libswresample/swresample.h>
    #include <stdio.h>
    #include <sys/ioctl.h>
    #include <linux/videodev2.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    #include <poll.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <arpa/inet.h>
    #include <pthread.h>
    #include <signal.h>
    #include <unistd.h>
    #include <string.h>
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , timer(new QTimer(this))
{
    ui->setupUi(this);
    if( v4l2_init() == -1 || ffmpeg_init() == -1){
        exit(-1);
    }

    // Set up timer for frame capture (approx. 25 FPS)
    connect(timer, &QTimer::timeout, this, &MainWindow::captureAndDisplayFrame);
    timer->start(1000 / FPS);
}

MainWindow::~MainWindow()
{
    delete ui;
}

